#include<stdio.h>
#include<stdlib.h>

typedef struct head
{
    int n;
    struct numbers *next;
}head;

typedef struct numbers
{
    int data;
    struct numbers *next;
}numbers;

head *Create()
{
    head *h;
    numbers *p;
    numbers *t;
    numbers *end;

    p=(numbers*)malloc(sizeof(numbers*));
    end=(numbers*)malloc(sizeof(numbers*));
    h=(head*)malloc(sizeof(head*));

    end->data = -1;
    end->next = NULL;
    while (1)
    {
        scanf("%d",&p->data);
        if (p->data == -1) {t->next = end;break;}
        p->next=NULL;

        if (h->n == 0)
        {
            h->next=p;        
        }
        else t->next=p;
        t=p;
        p=(numbers*)malloc(sizeof(numbers*));
        h->n++;
    }
    
    return h;
}

head *Select(head *h1,head *h2)
{
    head *h;
    h=(head*)malloc(sizeof(head*));
    h->n = 0;

    numbers *p1,*p2,*t;
    p1 = h1->next;
    p2 = h2->next;
    t = p1;
    for (;;)
    {
        if (p1->data == -1||p2->data == -1)
        {
            break;
        }
        
        if (p1->data==p2->data)
        {

            if (h->n == 0)
            {
                h->next = p1;
            }
            else t->next = p1;
        
            t = p1;
            h->n++;
            p1 = p1->next;
        }
        else if (p1->data>p2->data)
        {
            p2 = p2->next;
        }
        else if (p1->data<p2->data)
        {
            p1 = p1->next;
        }
        
        
    }

    return h;
}

int main(void)
{
    head *h1,*h2,*h3;
    numbers *p;

    h1 = Create();
    h2 = Create();
    h3 = Select(h1,h2);

    if (h3->n == 0)
    {
        printf("NULL");
        return 0;
    }
    else
    {
        p = h3->next;
        for (int i = 0; i < h3->n; i++)
        {
            printf("%d ",p->data);
            p = p->next;
        }
        
    }

    return 0;
}